 /** 
  * @brief        : 节流函数
  * @param         {*} func: 函数
  * @param         {*} delay: 延迟事件
  * @param         {*} immediate: 是否最开始立即执行一次
  * @return        {*} 返回截留函数
  **/
 export function throttle(func, delay, immediate = true) {
    let lastCalledTime = immediate ? 0 : Date.now();
    return function(...args) {
      const now = Date.now();
      if (now - lastCalledTime >= delay) {
        func.apply(this, args);
        lastCalledTime = now;
      }
    };
}

/** 
 * @brief        : 防抖函数
 * @param         {*} func:
 * @param         {*} delay:
 * @return        {*}
 **/
export function debounce(func, delay) {
    let timeoutId;
    
    return function(...args) {
      clearTimeout(timeoutId);
      
      timeoutId = setTimeout(() => {
        func(...args);
      }, delay);
    };
}

/** 
 * @brief        : 获取当前时间
 * @return        {*}
 **/
export function getCurrentFormattedTime() {
  const now = new Date();

  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  const seconds = String(now.getSeconds()).padStart(2, '0');

  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}


  
  